
import { capitalize } from "lodash";
import type { NavigationGuardNext, RouteRecordRaw, Router } from "vue-router";


// 聊天室判断权限
const chatAuth = (toPath: string, next: NavigationGuardNext) => {
  const hasToken = localStorage.getItem('token')
  if (hasToken) {
    if (toPath === '/chat/index') next()
    else next('/chat/index')
  } else {
    if (toPath == '/chat/index') next('/chat/login')
    else next()
  }
}

export const useRouterGuard = (router: Router) => {
  // 路由守卫
  let registerRouteFresh = true
  // 前置路由
  router.beforeEach((to, from, next) => {
    if (to.path.includes('/chat')) {
      chatAuth(to.path, next)
    }
    next()
  })

  // 全局解析守卫
  router.beforeResolve(async (_to) => {});

  // 全局后置钩子
  router.afterEach((_to, _from) => {});
};
